package app.server.project.main.service.db.dao.user;

import app.server.project.main.service.db.entity.user.UserUSDTEntity;
import app.server.project.main.service.db.mapper.user.UserUSDTMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Repository;

import java.util.Objects;

@Repository
public class UserUSDTDao extends ServiceImpl<UserUSDTMapper, UserUSDTEntity> {


    @Cacheable(key = "#userId", cacheNames = "app.server.project.main.service.db.dao.UserWalletDao.UserUSDTDao")
    public UserUSDTEntity getDataBy(long userId) {
        var data = this.getOne(Wrappers.<UserUSDTEntity>lambdaQuery()
                .eq(UserUSDTEntity::getId, userId));
        if (Objects.isNull(data)) {
            //缓存没有,就往库中写入一条数据
            data = UserUSDTEntity.of(userId);
        }
        data.setSynDb(true);
        return data;
    }


}
